package com.myprojects.common.util;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class FileIO {

    public static void main(String[] args) throws Exception{
        List<String> stringList = new ArrayList<>();
        String path = "D:\\idea_projects\\my_personnel_system\\web-resources\\src\\main\\webapp\\static\\js\\urlInterface.js";

        FileInputStream fileInputStream = new FileInputStream(path);
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));

        String line = null;
        while ((line = bufferedReader.readLine()) != null) {
            System.out.println(line);
            stringList.add(line);
        }


        File file = new File(path);
        FileOutputStream fileOutputStream = new FileOutputStream(file,true);
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fileOutputStream));
        for (String string : stringList){
            String newLine = string;
//            newLine = newLine.replace("model.addAttribute(\"","let ");
//            newLine = newLine.replace("\", \"\\"," = ");
//            newLine = newLine.replace("\\\"\");","\";");
            newLine = newLine.replace("9000","\"+webResourcesPort+\"");
            newLine = newLine.replace("9002","\"+userManagePort+\"");
            newLine = newLine.replace("9003","\"+deptEmpManagePort+\"");
            newLine = newLine.replace("9004","\"+permissionPort+\"");
//            newLine = newLine.replace("9002","\"+permissionConsumerPort+\"");

            writer.write(newLine);
            writer.newLine();
        }


        fileInputStream.close();
        writer.close();
        fileOutputStream.close();

    }

}
